﻿// Example header text. Can be configured in the options.
using System;
using System.Threading;
using System.Windows.Forms;

namespace vtech_system
{
    public partial class frmSplash : Telerik.WinControls.UI.RadForm
    {
        // Threading.
        private static frmSplash _fSplash = null;
        private static Thread _oThread = null;

        // Fade in and out.
        private double _opacityIncrement = .05;
        private double _opacityDecrement = .08;
        private const int TIMER_INTERVAL = 50;

        public frmSplash()
        {
            this.InitializeComponent();
            this.Opacity = .00;
            this.tmrTick.Interval = TIMER_INTERVAL;
            this.tmrTick.Start();
        }

        // Static methods.
        public static void ShowSplashScreen()
        {
            // Make sure it's only launched once.
            if (_fSplash != null)
            {
                return;
            }
            _oThread = new Thread(new ThreadStart(frmSplash.ShowForm));
            _oThread.IsBackground = true;
            _oThread.SetApartmentState(ApartmentState.STA);
            _oThread.Start();
            _oThread.Join();
        }

        // A private entry point for the thread.
        private static void ShowForm()
        {
            _fSplash = new frmSplash();
            Application.Run(_fSplash);
        }

        private void tmrTick_Tick(object sender, EventArgs e)
        {
            this.Opacity += this._opacityIncrement;
            if (this.Opacity >= 1)
            {
                this._opacityIncrement = -this._opacityDecrement;
            }
            if (this.Opacity <= 0)
            {
                this.tmrTick.Stop();
                this.Close();
            }
        }

        private void frmSplash_Load(object sender, EventArgs e)
        {
            this.Size = this.BackgroundImage.Size;
        }
    }
}